package com.example.adopt.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.adopt.entity.Adoptinfo;
import com.example.adopt.entity.Pet;
import com.example.adopt.service.AdoptinfoService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wjl
 * @since 2024-09-13
 */
@RestController
@RequestMapping("/adoptinfo")
public class AdoptinfoController {
    @Autowired
    AdoptinfoService adoptinfoService;
    @RequestMapping("/pets")
    public String selectAllpets(String petname,Integer status,String adoptorname,
                                Integer page,Integer size) throws JsonProcessingException {
        QueryWrapper<Adoptinfo> petWrapper = new QueryWrapper<>();
        if(!StrUtil.isBlank(petname)){
            petWrapper.like("petname", petname);
        }
        if(!StrUtil.isBlankIfStr(status)){
            petWrapper.like("status", status);
        }
        if(!StrUtil.isBlank(adoptorname)){
            petWrapper .like("adoptorname", adoptorname);
        }
        Page<Adoptinfo> petPage = new Page<>(page, size);
        IPage<Adoptinfo> petIPage = adoptinfoService.page(petPage,petWrapper);
        ObjectMapper objectMapper = new ObjectMapper();
        String s = objectMapper.writeValueAsString(petIPage);
        return s;
    }

}

